package com.xiangxiangjd.utils;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串常用工具类
 *
 * @author bool
 * @date 2019-05-15 11:40
 */
public class StringUtilsXiao {

    /**
     * 判断是否为空字符
     *
     * @param str
     * @return
     */
    public static boolean isBlank(String str) {
        return str == null || "".equals(str);
    }


    /**
     * 将MAP转换成一个xml格式，格式为<xml><key>value</key>...</xml>
     *
     * @param params
     * @return
     */
    public static String mapToXml(Map<String, String> params) {
        StringBuffer sb = new StringBuffer("<xml>");
        for (String key : params.keySet()) {
            sb.append("<")
                    .append(key).append(">")
                    .append(params.get(key))
                    .append("</").append(key).append(">");
        }

        sb.append("</xml>");
        return sb.toString();
    }

    //判断字符串是否为整数
    public static boolean isNumericInt(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }

    //判断字符串是否为整数或者小数
    public static boolean isNumeric(String str) {

        Pattern pattern = Pattern.compile("[0-9]*\\.?[0-9]+");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }




    public static void main(String[] args) {

        System.out.println(isNumericInt("111.1"));
        System.out.println(isNumeric("1111.11"));




    }

}
